﻿#pragma once

#include "svgshape.h"

class SvgWriter : public ShapeVisitor<void>
{
public:
	SvgWriter(const SvgShapeVec& shapes, QTextStream& m_stream, double height, double width);

	void Save();
	// background 可以不写的，所以这样初始化
	void SetBackground(const QColor& color);

public:
	static bool Save(const SvgShapeVec& shapes, const QString& fileName, const QColor& background, double height, double width);

protected:
	void _VisitLine(SvgLine& line) override;
	void _VisitRect(SvgRect& rect) override;
	void _VisitEllipse(SvgEllipse& ellipse) override;
	void _VisitPolygon(SvgPolygon& polygon) override;
	void _VisitText(SvgText& text) override;
	void _VisitPath(SvgPath& path) override;

private:
	void _WriteStart();
	void _WriteEnd() const;

	void _WriteShapeEnd(SvgShape& shape) const;
	void _WritePenProp(const QPen& pen) const;
	void _WriteBrushProp(const QBrush& brush) const;

private:
	const SvgShapeVec& m_shapes;
	QTextStream& m_stream;
	double m_height;
	double m_width;
	QColor m_background;
};